/* Copyright 2014 Sheldon Neilson www.neilson.co.za
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 */
package com.icetec.iceintel.service;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.icetec.iceintel.model.Alarm;
import com.icetec.iceintel.ui.activity.AlarmAlertActivity;
import com.icetec.iceintel.ui.activity.StaticWakeLock;




public class AlarmAlertBroadcastReciever extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {

        //受到闹钟广播之后，再次启动闹钟服务，进行下一个闹钟的调度
		Intent mathAlarmServiceIntent = new Intent(context,
				AlarmServiceBroadcastReciever.class);
		context.sendBroadcast(mathAlarmServiceIntent, null);


      //加锁，防止其它闹钟响应
		StaticWakeLock.lockOn(context);

      //获得广播传入的闹钟
		Bundle bundle = intent.getExtras();
		final Alarm alarm = (Alarm) bundle.getSerializable("alarm");

      //启动这个闹钟并且响应
		Intent AlarmAlertActivityIntent;
		AlarmAlertActivityIntent = new Intent(context, AlarmAlertActivity.class);
		AlarmAlertActivityIntent.putExtra("alarm", alarm);
		AlarmAlertActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(AlarmAlertActivityIntent);
	}

}
